package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.mapper.LhkRoomMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.LhkRoomTypeMapper;
import com.ruoyi.system.domain.LhkRoomType;
import com.ruoyi.system.service.ILhkRoomTypeService;

/**
 * 房间类型管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-28
 */
@Service
public class LhkRoomTypeServiceImpl implements ILhkRoomTypeService 
{
    @Autowired
    private LhkRoomTypeMapper lhkRoomTypeMapper;

    @Autowired
    private LhkRoomMapper lhkRoomMapper;

    /**
     * 查询房间类型管理
     * 
     * @param roomTypeId 房间类型管理主键
     * @return 房间类型管理
     */
    @Override
    public LhkRoomType selectLhkRoomTypeByRoomTypeId(Long roomTypeId)
    {

        return lhkRoomTypeMapper.selectLhkRoomTypeByRoomTypeId(roomTypeId);
    }

    /**
     * 查询房间类型管理列表
     * 
     * @param lhkRoomType 房间类型管理
     * @return 房间类型管理
     */
    @Override
    public List<LhkRoomType> selectLhkRoomTypeList(LhkRoomType lhkRoomType)
    {
        List<LhkRoomType> lhkRoomTypes = lhkRoomTypeMapper.selectLhkRoomTypeList(lhkRoomType);
        lhkRoomTypes.forEach(lhkRoomType1 -> {
            // 获取可用房间数量 -- 将hotelId变为Long类型
            Integer roomCount = lhkRoomMapper.selectLhkRoomByHotelIdAndRoomTypeId(lhkRoomType1.getManagerId(), lhkRoomType1.getRoomTypeId()).size();
            lhkRoomType1.setFreeRooms(roomCount);
        });
        return lhkRoomTypes;
    }

    /**
     * 新增房间类型管理
     * 
     * @param lhkRoomType 房间类型管理
     * @return 结果
     */
    @Override
    public int insertLhkRoomType(LhkRoomType lhkRoomType)
    {
        lhkRoomType.setCreateTime(DateUtils.getNowDate());
        return lhkRoomTypeMapper.insertLhkRoomType(lhkRoomType);
    }

    /**
     * 修改房间类型管理
     * 
     * @param lhkRoomType 房间类型管理
     * @return 结果
     */
    @Override
    public int updateLhkRoomType(LhkRoomType lhkRoomType)
    {
        lhkRoomType.setUpdateTime(DateUtils.getNowDate());
        return lhkRoomTypeMapper.updateLhkRoomType(lhkRoomType);
    }

    /**
     * 批量删除房间类型管理
     * 
     * @param roomTypeIds 需要删除的房间类型管理主键
     * @return 结果
     */
    @Override
    public int deleteLhkRoomTypeByRoomTypeIds(Long[] roomTypeIds)
    {
        return lhkRoomTypeMapper.deleteLhkRoomTypeByRoomTypeIds(roomTypeIds);
    }

    /**
     * 删除房间类型管理信息
     * 
     * @param roomTypeId 房间类型管理主键
     * @return 结果
     */
    @Override
    public int deleteLhkRoomTypeByRoomTypeId(Long roomTypeId)
    {
        return lhkRoomTypeMapper.deleteLhkRoomTypeByRoomTypeId(roomTypeId);
    }
}
